#pragma once
#include <memory>
#include <climits>

#include "Protocol.hpp"

class Calculate
{
public:
    Calculate()
    {
    }
    std::shared_ptr<Response> Operation(std::shared_ptr<Request> reqPtr)
    {
        int x = reqPtr->RetX();
        int y = reqPtr->RetY();
        char oper = reqPtr->RetOper();
        std::shared_ptr<Response> resPtr = std::make_shared<Response>();
        switch (oper)
        {
        case '+':
        {
            resPtr->_result = x + y;
            break;
        }
        case '-':
        {
            resPtr->_result = x - y;
            break;
        }
        case '*':
        {
            resPtr->_result = x * y;
            break;
        }
        case '/':
        {
            if (y == 0)
            {
                resPtr->_result = INT_MAX;
                resPtr->_code = 1;
                resPtr->_describe = "Division by zero error";
            }
            else
            {
                resPtr->_result = x / y;
            }
            break;
        }
        default:
        {
            resPtr->_result = INT_MIN;
            resPtr->_code = 2;
            resPtr->_describe = "Other illegal operations";
            break;
        }
        }
        return resPtr;
    }
    ~Calculate()
    {
    }

private:
};